package com.infore.airsupervise.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.LawingSiteE;

import java.util.List;

/**
 *  现场执法 笔录  问答 模板 适配器
 * Created by xiaotao on 2017/5/22.
 */

public class SiteModelAdapter extends BaseQuickAdapter<LawingSiteE.NoteModel,BaseViewHolder>  {

    public SiteModelAdapter(int layoutResId, List<LawingSiteE.NoteModel> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final LawingSiteE.NoteModel item) {
        final EditText answer = helper.getView(R.id.et_answer);
        final EditText question = helper.getView(R.id.et_question);
        answer.setText(item.getAnswer());
        question.setText(item.getQuestion());
        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.tv_insert :
                        addData(new LawingSiteE.NoteModel());//插入
                        break;
                    case R.id.tv_delete :
                        answer.getText().clear();
                        question.getText().clear();
                        remove(helper.getAdapterPosition()); //删除
                        break;
                }
            }
        };
        helper.getView(R.id.tv_delete).setOnClickListener(clickListener);
        helper.getView(R.id.tv_insert).setOnClickListener(clickListener);

        answer.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                    item.setAnswer(s.toString());
            }
        });

        question.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setQuestion(s.toString());
            }
        });
    }


}
